package myTest;

import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RegexTest {
    public static void main(String[] args) {
        String testString1 = "cz201502151111110001";
        String testString2 = "201402151111110001";
        String regex = "^\\w*(\\d{18}$)";
        String regex1 = "^\\w*((2014|2015)\\d{14}$)";
        System.out.println(Pattern.matches(regex1, testString1));
        System.out.println(Pattern.matches(regex1, testString2));
        Pattern pattern = Pattern.compile(regex1);
        Matcher matcher = pattern.matcher(testString1);
        if (matcher.find()) {
            System.out.println(matcher.group());
            System.out.println(matcher.group(1));
        }

        char[] s = new char[12];

        new String(s);


    }

    public String replaceSpace(String s) {
        // write code here
        int length = s.length();
        int nLength = 0;
        for (int i = 0; i < length; i++) {
            if (s.charAt(i) == ' ') {
                nLength += 3;
            } else {
                nLength++;
            }
        }
        char[] newStr = new char[nLength];
        int oi = 0;
        int ni = 0;
        for (; oi < s.length(); oi++) {
            if (s.charAt(oi) == ' ') {
                newStr[ni++] = '%';
                newStr[ni++] = '2';
                newStr[ni++] = '0';
            } else {
                newStr[ni++] = s.charAt(oi);
            }
        }
        return new String(newStr);

    }

    public ArrayList<Integer> printMatrix(int[][] matrix) {

        if (matrix.length == 0) {
            return new ArrayList<>();
        }
        if (matrix[0].length == 0) {
            return new ArrayList<>();
        }

        ArrayList<Integer> result = new ArrayList<>(matrix.length * matrix[0].length);
        int top = 0;
        int bottom = matrix.length - 1;
        int left = 0;
        int right = matrix[0].length - 1;
        while (true) {
            int col = left;
            for (; col <= right; col++) {
                result.add(matrix[top][col]);
            }
            top++;
            if (top > bottom) {
                break;
            }
            int row = top;
            for (; row <= bottom; row++) {
                result.add(matrix[row][right]);
            }
            right--;
            if (right < left) {
                break;
            }
            col = right;
            for (; col >= left; col--) {
                result.add(matrix[bottom][col]);
            }
            bottom--;
            if (top > bottom) {
                break;
            }
            row = bottom;
            for (; row >= top; row--) {
                result.add(matrix[row][left]);
            }
            left++;
            if (right < left) {
                break;
            }
        }
        return result;
    }
}
